﻿using System.Collections.Generic;
using SmartHRMS.Model.Account;
using SmartHRMS.Infrastructure;
using SmartHRMS.Infrastructure.Caching;

namespace SmartHRMS.Services
{
   public class ModuleService: IModuleService
    {
        private IModuleRepository _IModuleRepository;
        private IUnitOfWork _UnitOfWork;
        private ICacheStorage _CacheStorage;
        string storageCacheKey = "modules";

        public ModuleService(IModuleRepository moduleRepository, IUnitOfWork UnitOfWork, ICacheStorage CacheStorage)
        {
            this._IModuleRepository = moduleRepository;
            this._CacheStorage = CacheStorage;
            this._IModuleRepository.Inject(UnitOfWork);
            this._UnitOfWork = UnitOfWork;
        }


        #region IModuleService Members

        public IList<Module> FindAll()
        {
            IList<Module> modules;
            modules = _CacheStorage.Retrieve<List<Module>>(storageCacheKey);
            if (modules == null)
            {
                modules = _IModuleRepository.FindAll();
                _CacheStorage.Store(storageCacheKey, modules);
            }
            return modules;
        }

        #endregion
    }
}
